/**
* Created by yyr on 2018/1/18
*已设立基金显示选项卡闲散理财
*/
<template>
    <div>
        <div class="ca-box-border-top-none ca-p-22" v-if="!isFundIdleFinancingEdit">
            <el-row>
                <el-col :span="12" class="ca-title  clearfix">
                    <h3>闲散理财</h3>
                </el-col>
                <el-col :span='12' class="ca-align-right">
                    <el-button type="text"  :disabled="!isAuthIdleEdit" @click="fundIdleEdit()" class="ca-edit-btn el-icon-edit">编辑</el-button>
                </el-col>
            </el-row>
            <el-table
                :data="idleDataList"
                stripe
                border
                style="width:100%" class="ca-table table_p_01">
                <el-table-column
                    show-overflow-tooltip
                    prop="purchase"
                    label="买入时间">
                    <template slot-scope="scope">
                        <span>{{scope.row.purchase==='合计'?'合计':$moment( scope.row.purchase).format("YYYY-MM-DD")}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="productName"
                    label="产品名称">
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="total"
                    label="购买总额(万元)">
                    <template slot-scope="scope">
                        {{scope.row.total | format1}}
                    </template>
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="yield"
                    label="预期年化收益率（%）">
                    <template slot-scope="scope">
                        {{scope.row.yield | format1}}%
                    </template>
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="redeem"
                    label="赎回时间">
                    <template slot-scope="scope">
                        <span>{{scope.row.redeem==='--'?'--':$moment( scope.row.redeem).format("YYYY-MM-DD")}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="profit"
                    label="净收益(万元)">
                    <template slot-scope="scope">
                        {{scope.row.profit | format1}}
                    </template>
                </el-table-column>
                <el-table-column
                    show-overflow-tooltip
                    prop="remarks"
                    label="备注">
                </el-table-column>
            </el-table>
        </div>
        <csFundIdleFinancingEdit v-if="isFundIdleFinancingEdit" @isEdit="isEdit" @addRedDot="addRedDot"></csFundIdleFinancingEdit>
    </div>
</template>

<script type="text/ecmascript-6">
    import {api} from '../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import {isNoAuth} from '__service/utils';
    export default {
        data() {
            return {
                isAuthIdleEdit: isNoAuth('已投资基金-闲散理财-编辑'),
                itemId: this.$route.params.fundId,
                isFundIdleFinancingEdit: false,//选项卡[4]闲散理财
                idleDataList: [],
            }
        },
        props: {
        },
        beforeRouteEnter(to, from, next) {
            next(vm=>{
                vm.getFundIdleList();
            });
        },
        created() {
            this.getFundIdleList();
        },
        methods: {
            //切换编辑和保存
            fundIdleEdit() {
                this.isFundIdleFinancingEdit = true;
            },
            //获取列表
            getFundIdleList() {
                apiHttp(api.GET_FUND_IDLE,{id: this.itemId}).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        let total = 0;
                        let profit = 0;
                        let yield1 = 0;
                        for (let i of ret.data) {
                            total = Number(total) + Number(i.total);
                            profit = Number(profit) + Number(i.profit);
                            yield1 = Number(i.yield) + Number(i.yield);
                        }
                        let totalData = [{
                            purchase: '合计',
                            productName: '--',
                            total: total,
                            yield: yield1,
                            redeem: '--',
                            profit: profit,
                            remarks: '--'
                        }]
                        this.idleDataList = ret.data.concat(totalData);
                    }
                })
            },
            isEdit(val) {
                this.isFundIdleFinancingEdit = val;
                this.getFundIdleList();
            },
            addRedDot() {
                this.$emit('addRedDot', 9)
            }
        },
        components: {
            'csFundIdleFinancingEdit': require('./edit.vue'),//选项卡基金信息》闲散理财 edit
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>

</style>
